
public class TrainController {
	private TrainModel associatedTrainModel;
	private double curSpd;
	private double desSpd;
	private TrainControllerPanel tcp;
	
	public void receive(TNBundle b) throws InterruptedException{
		Thread.sleep(3000);
		curSpd = b.currentSpeed;
		desSpd = b.newSpeed;
		double mass = b.mass;
		double power = 0;
		double[] accelerationLimits = b.accelerationLimits;
		
		tcp.status = "Bundle: Train Model bundle received.";
		System.out.println(tcp.status);
		tcp.lblBundle.setText(tcp.status);
		
		Thread.sleep(1000);
		tcp.speed = ("Speed: "+ b.currentSpeed);
		System.out.println(tcp.speed);
		tcp.lblSpeed.setText(tcp.speed);
		
		tcp.power = ("Power: "+ power);
		System.out.println(tcp.power);
		tcp.lblPower.setText(tcp.power);
		
		//Test speed
		if((curSpd+desSpd)>=0)
		curSpd=curSpd+desSpd;
		else
		curSpd=0;
		
		b.currentSpeed = curSpd;
		
		Thread.sleep(3000);
		tcp.speed = ("Speed: "+ b.currentSpeed);
		System.out.println(tcp.speed);
		tcp.lblSpeed.setText(tcp.speed);
		
		Thread.sleep(1000);
		power = accelerationLimits[0]*mass*curSpd;
		tcp.status = "Bundle: Train Model bundle sent.";
		System.out.println(tcp.status);
		tcp.lblBundle.setText(tcp.status);
		//associatedTrainModel.setVelocity(b.currentSpeed);
		tcp.power = ("Power: "+ power);
		System.out.println(tcp.power);
		tcp.lblPower.setText(tcp.power);
		associatedTrainModel.setPower(power);
	}
	
	public TrainController(TrainModel associatedTrainModel)
	{
		tcp = new TrainControllerPanel();
		this.associatedTrainModel = associatedTrainModel;
	}
}